﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataRow Convert2ICC_GB1109(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_GB1109(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {

                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_GB1109(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_GB1109(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            switch (ITXDBVERSION)
            {
                case "JLT":
                case "YGR":
                default:
                    Result = QueryICC_GB1109(dwData);
                    if (Result.Tables.Count > 0)
                    {
                        tbLocal = Result.Tables[0];
                        if (tbLocal.Rows.Count > 0)
                        {
                            flgExist = true;
                            dwLocal = tbLocal.Rows[0];
                        }
                        else
                        {
                            dwLocal = tbLocal.NewRow();
                        }
                    }

                    MapICC_GB1109(ref dwLocal, dwData);

                    if (!flgExist)
                    {
                        //dwLocal["ABAID"] = GetSeq();
                        InsertICC_GB1109(dwLocal, 1);
                    }
                    UpdateICC_GB1109(dwLocal, 1);
                    break;
            }
        }
        public void DeleteICC_GB1109(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_GB1109 WHERE ABAID=:ABAID";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 2: 
                    break;
                case 3:
                    or1.CommandText = "DELETE FROM ICC_GB1109 WHERE RTRIM(ABFSTEP)=:ABFSTEP";
                    or1.Parameters.Add("ABFSTEP", OracleType.NVarChar).Value = dwData["ABFSTEP"].ToString().Trim();
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_GB1109(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1 = OracleDB.CreateCommand();
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            string FSARTPRGR = "";
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_GB1109 WHERE ROWNUM<2";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_GB1109 WHERE ABAID=:ABAID";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 2: 
                    break;
                case 3:
                    or1.CommandText = "SELECT MAX(ABAID) AS MAXORD FROM ICC_GB1109 WHERE RTRIM(TERMNO)=:TERMNO";
                    or1.Parameters.Add("TERMNO", OracleType.NVarChar).Value = dwData["TERMNO"].ToString().Trim();
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "ICC_GB1109";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateICC_GB1109(DataRow dwData, int option, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region
                    or1.CommandText = "UPDATE ICC_GB1109 SET "
                    +"ABAID=:ABAID,"
                    +"TERMNO=:TERMNO,"
                    +"PROCESSED=:PROCESSED,"
                    +"NEWDATE=:NEWDATE,"
                    +"NEWTIME=:NEWTIME,"
                    +"NEWUSER=:NEWUSER,"
                    +"CHGDATE=:CHGDATE,"
                    +"CHGTIME=:CHGTIME,"
                    +"CHGUSER=:CHGUSER,"
                    +"GLMANDANT=:GLMANDANT,"
                    +"GPSPPART=:GPSPPART,"
                    +"GPFBPART=:GPFBPART,"
                    +"GPZWPART=:GPZWPART,"
                    +"GLPARTIE=:GLPARTIE,"
                    +"GLPARTIEKZ=:GLPARTIEKZ,"
                    +"GPGART=:GPGART,"
                    +"GPGVAR=:GPGVAR,"
                    +"GPGFARBE=:GPGFARBE,"
                    +"GLLBEH=:GLLBEH,"
                    +"GLLBEHI=:GLLBEHI,"
                    +"GLBSTNET=:GLBSTNET,"
                    +"GLBSTKG=:GLBSTKG,"
                    + "GLKOND=:GLKOND,"
                    +"GLBSTKA=:GLBSTKA,"
                    +"GLBSTSP=:GLBSTSP,"
                    +"TARGETQTY=:TARGETQTY,"
                    +"GLLO=:GLLO,"
                    +"GLLB=:GLLB,"
                    +"GLLP=:GLLP,"
                    +"CPLO=:CPLO,"
                    +"CPLB=:CPLB,"
                    +"CPLP=:CPLP,"
                    +"JP01=:JP01,"
                    +"JP02=:JP02,"
                    +"JP03=:JP03,"
                    +"JP04=:JP04,"
                    +"JP05=:JP05,"
                    +"JP06=:JP06,"
                    +"JP07=:JP07,"
                    +"JP08=:JP08,"
                    +"JP09=:JP09,"
                    +"JP10=:JP10 "
                    #endregion
                    + " WHERE ABAID=:ABAID";
                    #region 
                         or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                         or1.Parameters.Add("TERMNO", OracleType.NVarChar).Value = dwData["TERMNO"].ToString();
                         or1.Parameters.Add("PROCESSED", OracleType.NVarChar).Value = dwData["PROCESSED"].ToString();
                         or1.Parameters.Add("NEWDATE", OracleType.NVarChar).Value = dwData["NEWDATE"].ToString();
                         or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString();
                         or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString();
                         or1.Parameters.Add("CHGDATE", OracleType.NVarChar).Value = dwData["CHGDATE"].ToString();
                         or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString();
                         or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString();
                         or1.Parameters.Add("GLMANDANT", OracleType.NVarChar).Value = dwData["GLMANDANT"].ToString();
                         or1.Parameters.Add("GPSPPART", OracleType.NVarChar).Value = dwData["GPSPPART"].ToString();
                         or1.Parameters.Add("GPFBPART", OracleType.NVarChar).Value = dwData["GPFBPART"].ToString();
                         or1.Parameters.Add("GPZWPART", OracleType.NVarChar).Value = dwData["GPZWPART"].ToString();
                         or1.Parameters.Add("GLPARTIE", OracleType.NVarChar).Value = dwData["GLPARTIE"].ToString();
                         or1.Parameters.Add("GLPARTIEKZ", OracleType.NVarChar).Value = dwData["GLPARTIEKZ"].ToString();
                         or1.Parameters.Add("GPGART", OracleType.NVarChar).Value = dwData["GPGART"].ToString();
                         or1.Parameters.Add("GPGVAR", OracleType.NVarChar).Value = dwData["GPGVAR"].ToString();
                         or1.Parameters.Add("GPGFARBE", OracleType.NVarChar).Value = dwData["GPGFARBE"].ToString();
                         or1.Parameters.Add("GLLBEH", OracleType.NVarChar).Value = dwData["GLLBEH"].ToString();
                         or1.Parameters.Add("GLLBEHI", OracleType.NVarChar).Value = dwData["GLLBEHI"].ToString();
                         or1.Parameters.Add("GLBSTNET", OracleType.NVarChar).Value = dwData["GLBSTNET"].ToString();
                         or1.Parameters.Add("GLBSTKG", OracleType.NVarChar).Value = dwData["GLBSTKG"].ToString();
                         or1.Parameters.Add("GLKOND", OracleType.NVarChar).Value = dwData["GLKOND"].ToString();                    
                         or1.Parameters.Add("GLBSTKA", OracleType.NVarChar).Value = dwData["GLBSTKA"].ToString();
                         or1.Parameters.Add("GLBSTSP", OracleType.NVarChar).Value = dwData["GLBSTSP"].ToString();
                         or1.Parameters.Add("TARGETQTY", OracleType.NVarChar).Value = dwData["TARGETQTY"].ToString();
                         or1.Parameters.Add("GLLO", OracleType.NVarChar).Value = dwData["GLLO"].ToString();
                         or1.Parameters.Add("GLLB", OracleType.NVarChar).Value = dwData["GLLB"].ToString();
                         or1.Parameters.Add("GLLP", OracleType.NVarChar).Value = dwData["GLLP"].ToString();
                         or1.Parameters.Add("CPLO", OracleType.NVarChar).Value = dwData["CPLO"].ToString();
                         or1.Parameters.Add("CPLB", OracleType.NVarChar).Value = dwData["CPLB"].ToString();
                         or1.Parameters.Add("CPLP", OracleType.NVarChar).Value = dwData["CPLP"].ToString();
                         or1.Parameters.Add("JP01", OracleType.NVarChar).Value = dwData["JP01"].ToString();
                         or1.Parameters.Add("JP02", OracleType.NVarChar).Value = dwData["JP02"].ToString();
                         or1.Parameters.Add("JP03", OracleType.NVarChar).Value = dwData["JP03"].ToString();
                         or1.Parameters.Add("JP04", OracleType.NVarChar).Value = dwData["JP04"].ToString();
                         or1.Parameters.Add("JP05", OracleType.NVarChar).Value = dwData["JP05"].ToString();
                         or1.Parameters.Add("JP06", OracleType.NVarChar).Value = dwData["JP06"].ToString();
                         or1.Parameters.Add("JP07", OracleType.NVarChar).Value = dwData["JP07"].ToString();
                         or1.Parameters.Add("JP08", OracleType.NVarChar).Value = dwData["JP08"].ToString();
                         or1.Parameters.Add("JP09", OracleType.NVarChar).Value = dwData["JP09"].ToString();
                         or1.Parameters.Add("JP10", OracleType.NVarChar).Value = dwData["JP10"].ToString();
                    #endregion
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void InsertICC_GB1109(DataRow dwData, int option, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO ICC_GB1109 (ABAID,TERMNO) VALUES (:ABAID,:TERMNO)";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    or1.Parameters.Add("TERMNO", OracleType.NVarChar).Value = dwData["TERMNO"].ToString(); 
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
